document.addEventListener('DOMContentLoaded', function() {
    const loginForm = document.getElementById('loginForm');
    const togglePassword = document.getElementById('togglePassword');
    const passwordInput = document.getElementById('password');

    // 处理密码显示/隐藏
    togglePassword.addEventListener('click', function() {
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);
        
        // 切换图标
        const icon = this.querySelector('i');
        icon.classList.toggle('fa-eye');
        icon.classList.toggle('fa-eye-slash');
    });

    // 处理登录表单提交
    loginForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;

        if (username === 'admin' && password === 'admin') {
            // 显示成功提示
            showLoginMessage('登录成功，正在跳转...', 'success');
            
            // 延迟跳转到主页
            setTimeout(() => {
                window.location.href = 'index.html';
            }, 1500);
        } else {
            // 显示错误提示
            showLoginMessage('用户名或密码错误', 'error');
        }
    });
});

// 显示登录消息
function showLoginMessage(message, type) {
    // 移除现有消息
    const existingMessage = document.querySelector('.login-message');
    if (existingMessage) {
        existingMessage.remove();
    }

    // 创建新消息
    const messageDiv = document.createElement('div');
    messageDiv.className = `login-message ${type}`;
    messageDiv.innerHTML = `
        <i class="fas fa-${type === 'success' ? 'check-circle' : 'exclamation-circle'}"></i>
        ${message}
    `;

    // 添加到表单后面
    document.querySelector('.login-form').appendChild(messageDiv);

    // 自动移除消息
    if (type === 'error') {
        setTimeout(() => {
            messageDiv.remove();
        }, 3000);
    }
} 